package xyz.lilei123.sessiondemo.service.impl;

import org.springframework.stereotype.Service;
import xyz.lilei123.sessiondemo.dto.UserDto;
import xyz.lilei123.sessiondemo.service.IUserService;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author jack
 * @version 1.0
 * @date 05/09/2021 17:17
 **/
@Service
public class UserServiceImpl implements IUserService {

    private Map<String, UserDto> userMap = new HashMap<>(8);

    @PostConstruct
    public void loadUser(){
        UserDto jack = new UserDto();
        jack.setId("1");
        jack.setPassword("123456");
        jack.setUsername("Jack");
        userMap.put(jack.getUsername(), jack);
        UserDto lily = new UserDto();
        lily.setId("2");
        lily.setPassword("123451");
        lily.setUsername("Lily");
        userMap.put(lily.getUsername(), lily);
    }

    @Override
    public UserDto getUserByName(String name){
        return userMap.get(name);
    }
}
